const getTime = function() {
	let time = new Date()
	const year = time.getFullYear()
	let month = time.getMonth() + 1
	const day = time.getDate()
	month = month < 10 ? '0' + month : month
	return String(year) + month + String(day)
}

const mouldData = function(dayTime) {
	let recordList = {}
	recordList[dayTime] = {
		'history': {
			total: 0,
			classify: {}
		},
		'geography': {
			total: 0,
			classify: {}
		},
		'botany': {
			total: 0,
			classify: {}
		},
		'animal': {
			total: 0,
			classify: {}
		}
	}
	return recordList
}


// 加积分
const addIntegral = function(data) {
	let dayTime = getTime()
	let dayTimeStorageData = uni.getStorageSync(dayTime) || ''
	let obj = {
		1: 'history',
		2: 'geography',
		3: 'botany',
		4: 'animal'
	}
	let Dat = dayTimeStorageData[dayTime]
	let nweAnswerId = []
	if (Dat[obj[data.typeId]].classify[data.subjectId]) {
		nweAnswerId = Dat[obj[data.typeId]].classify[data.subjectId].doneAnswer
	} else {
		[data.answerId]
	}
	nweAnswerId.push(data.answerId)
	let doneAnswer = new Set(nweAnswerId)
	Dat[obj[data.typeId]].total = Dat[obj[data.typeId]].total + 1
	Dat[obj[data.typeId]].classify[data.subjectId] = {
		name: data.name,
		subjectId: data.subjectId,
		integral: !Dat[obj[data.typeId]].classify[data.subjectId] ? 1 : Dat[obj[data.typeId]].classify[data
			.subjectId].integral + 1,
		doneAnswer: [...doneAnswer]
	}
	return {
		[dayTime]: Dat,
		integral: Dat[obj[data.typeId]].classify[data.subjectId].integral
	}
}

module.exports = {
	getTime,
	mouldData,
	addIntegral
}
